home *** CD-ROM | disk | FTP | other *** search
/ Amiga Plus Special 16 / AMIGAplus Sonderheft 16 (1998)(ICP)(DE)[!].iso / pd / anwendungen / amicad / arexx_english / savenets.amicad < prev    next >
Text File  |  1998-08-09  |  8KB  |  360 lines

  1. /* $VER: SaveNets 1.00e (© R.Florac, 09-08-98) */
  2.  
  3. options results
  4.  
  5. signal on error
  6. signal on syntax
  7.  
  8. j=1; nets=1;
  9. 'DEF NEXTJUNCTION(O)=OO=O:WHILE(IF(OO>0,TYPE(OO)<>7,0),IF(OO<OBJECTS(-1),OO=OO+1,OO=0)):OO'
  10. 'UNMARK(-1):LOCK(-1):OBJECTS(-1)'; objets=result
  11.  
  12. equi.=-1
  13. label.=""
  14.  
  15. 'TITLE("Reading labels...")'
  16. do i=1 to objets
  17.     'TYPE(O='i')'
  18.     if result=4 | result=12 | result=11 then do
  19.     'ABS(FINDLINE(1,COL(O),LINE(O)))'; j=result
  20.     if j>0 then do
  21.         'READTEXT(O)'; label=result
  22.         if datatype(label,"w") then label.label="LABEL_DÉJÀ_UTILISÉ"
  23.     end
  24.     end
  25. end
  26.  
  27. 'TITLE("Testing nets...")'
  28. i=1
  29. do while i>0
  30.     'OO=FINDOBJ('i',2,-1,-1)'; i=result
  31.     if result>0 then do
  32.     'TEST(OO)'
  33.     if result=0 then do
  34.         do while label.nets~=""
  35.         nets=nets+1
  36.         end
  37.         label.nets=nets
  38.         equi.i=nets
  39.         'COORDS(OO)'
  40.         parse var result x0','y0','x1','y1
  41.         call test_ligne(x0,y0,nets,objets)
  42.         call test_ligne(x1,y1,nets,objets)
  43.     end
  44.     if i=objets then i=0
  45.     else i=i+1
  46.     end
  47. end
  48.  
  49. 'TITLE("Testing junctions...")'
  50. i=1
  51. do while i>0
  52.     'I=FINDOBJ('i',7,-1,-1)'; i=result
  53.     if i>0 then do
  54.     'MARK(I):L1=ABS(FINDLINE(1,COL(I),LINE(I)))'; l1=result
  55.     if l1>0 & l1<objets then do
  56.         j=l1+1
  57.         do while j>0
  58.         'J=ABS(FINDLINE('j',COL(I),LINE(I)))'; j=result
  59.         if j>0 then do
  60.             if equi.j~=equi.l1 then do
  61.             call changer_labels(l1,j)
  62.             end
  63.             if j=objets then j=0
  64.             else j=j+1
  65.         end
  66.         end
  67.     end
  68.     if i=objets then i=0
  69.     else i=i+1
  70.     end
  71. end
  72.  
  73. 'TITLE("Looking for labels and connectors...")'
  74. do i=1 to objets
  75.     'TYPE(O='i')'
  76.     if result=4 | result=12 | result=11 then do
  77.     'ABS(FINDLINE(1,COL(O),LINE(O)))'; j=result
  78.     if j>0 then do
  79.         net=equi.j
  80.         'READTEXT(O)'; label=result
  81.         label.net=label
  82.     end
  83.     end
  84. end
  85.  
  86. 'TITLE("Looking for powers...")'
  87. do i=1 to objets
  88.     'FINDPART('i',"POWER SUPPLY")'; i=result
  89.     if i>0 then do
  90.     j=connexion_broche(i,1)
  91.     if j>0 then do
  92.         net=equi.j
  93.         'READTEXT(GETVAL('i'))'; label=result
  94.         label.net=label
  95.     end
  96.     end
  97.     else leave
  98. end
  99.  
  100. 'TITLE("Testing redundances...")'
  101. do i=1 to nets
  102.     do j=i+1 to nets
  103.     if label.j~="" then do
  104.         if label.i=label.j then do
  105.         do k=1 to objets
  106.             if equi.k=j then equi.k=i
  107.         end
  108.         label.j=""
  109.         end
  110.     end
  111.     end
  112. end
  113.  
  114. 'TITLE("Looking for grounds...")'
  115. do i=1 to objets
  116.     'FINDPART('i',"GROUND")'; i=result
  117.     if i>0 then do
  118.     j=connexion_broche(i,1)
  119.     if j>0 then do
  120.         equi.0=0; label.0=0
  121.         call changer_labels(0,j)
  122.     end
  123.     end
  124.     else leave
  125. end
  126.  
  127. do until c=0
  128.     'TITLE("Setting netlist ended"):SELECT("Choose an action"+CHR(10)+"Look for nets"+CHR(10)+"Check netlist"+CHR(10)+"Save netlist"+CHR(10)+"Abort script")'
  129.     select
  130.     when result=1 then call visu_equi
  131.     when result=2 then call controler_netlist
  132.     when result=3 then call sauver_netlist
  133.     otherwise c=0
  134.     end
  135. end
  136. exit
  137.  
  138. visu_equi:
  139.     'TITLE("Looking for nets"):UNMARK(-1)'
  140.     do i=0 to nets
  141.     if label.i ~= "LABEL_DÉJÀ_UTILISÉ" & label.i ~= "" then do
  142.         do j=1 to objets
  143.         if equi.j=i then 'MARK('j')'
  144.         end
  145.         'SELECT("Net 'label.i'"+CHR(10)+"Abort"+CHR(10)+"Continue"+CHR(10)+"Save netlist"+CHR(10)+"Check netlist")'
  146.         if result <= 1 then return
  147.         if result = 3 then do
  148.         call sauver_netlist
  149.         exit
  150.         end
  151.         if result = 4 then do
  152.         call controler_netlist
  153.         leave
  154.         end
  155.         'UNMARK(-1)'
  156.     end
  157.     end
  158.     return
  159.  
  160. test_ligne: procedure expose equi.
  161.     parse arg x0,y0,n,nbo
  162.     o=1
  163.     do until o=0
  164.     'X=FINDOBJ('o',2,'x0','y0')'; o=result
  165.     if o>0 then do
  166.         'IF(TEST(X),"",MARK(X):COORDS(X))'
  167.         if result~="" then do
  168.         parse var result x1','y1','x2','y2
  169.         equi.o=n
  170.         if x0=x1 & y0=y1 then call test_ligne(x2,y2,n,nbo)
  171.         else call test_ligne(x1,y1,n,nbo)
  172.         end
  173.         if o=nbo then o=0
  174.         else o=o+1
  175.     end
  176.     end
  177.     return
  178.  
  179. changer_labels: procedure expose equi. objets label.
  180.     parse arg o1,o2
  181.     if datatype(equi.o2,'w') then do
  182.     e=equi.o2
  183.     label.e=""
  184.     do i=1 to objets
  185.         if equi.i=e then equi.i=equi.o1
  186.     end
  187.     return o1
  188.     end
  189.     else do
  190.     e=equi.o1
  191.     label.e=""
  192.     do i=1 to objets
  193.         if equi.i=e then equi.i=equi.o2
  194.     end
  195.     return o2
  196.     end
  197.     return
  198.  
  199. test_jonction: procedure expose equi.
  200.     parse arg xj,yj,n,objets
  201.     obj=1
  202.     do while obj>0
  203.     'X=ABS(FINDLINE('obj','xj','yj'))'; obj=result
  204.     if obj>0 then do
  205.         if equi.obj=n then return 1
  206.         if obj=objets then return 0
  207.         obj=obj+1
  208.     end
  209.     end
  210.     return 0
  211.  
  212. controler_netlist:
  213.     'TITLE("Checking netlist...")'
  214.     i=1
  215.     do while i>0
  216.     'O=FINDOBJ('i',1,-1,-1)'; i=result
  217.     if i>0 then do
  218.         'PARTNAME(O)'
  219.         if result~="ALIMENTATION" & result ~="MASSE" then do
  220.         'IF(GETREF(O),READTEXT(GETREF(O)),PARTNAME(O)+"?")'
  221.         ligne=translate(result,"_"," ")||' '
  222.         'DEVPINS(O)'; j=result
  223.         do k=1 to j
  224.             l=connexion_broche(i,k)
  225.             if l>0 then do
  226.             net=equi.l
  227.             ligne=ligne||label.net||' '
  228.             end
  229.             else ligne=ligne||"-1"||' '
  230.         end
  231.         'IF(GETVAL(O),READTEXT(GETVAL(O)),PARTNAME(O))'
  232.         ligne=ligne||result
  233.         'UNMARK(-1):MARK(O):SELECT("'ligne'"+CHR(10)+"Continue"+CHR(10)+"Abort")'
  234.         if result~=1 then return
  235.         end
  236.         if i=objets then leave
  237.         i=i+1
  238.     end
  239.     end
  240.     'TITLE("")'
  241. return
  242.  
  243. sauver_netlist:
  244.     'TITLE(""):REQFILE("Netlist file to create","Spice")'
  245.     fichier=result
  246.     if fichier="" then return
  247.     'TITLE("Saving netlist...")'
  248.     if ~open(file, fichier, 'W') then return
  249.     'FILEPART("")'
  250.     writeln(file,result)
  251.     'DATE(1)+" à "+TIME(1)'
  252.     writeln(file,"* Created by AmiCAD, on "||result||" *")
  253.     do i=1 to objets
  254.     'O=FINDOBJ('i',1,-1,-1)'; i=result
  255.     if result>0 then do
  256.         'PARTNAME(O)'
  257.         if result~="POWER SUPPLY" & result ~="GROUND" then do
  258.         'IF(GETREF(O),READTEXT(GETREF(O)),PARTNAME(O)+"?")'
  259.         ligne=translate(result,"_"," ")||' '
  260.         'DEVPINS(O)'; j=result
  261.         do k=1 to j
  262.             l=connexion_broche(i,k)
  263.             if l>0 then do
  264.             net=equi.l
  265.             ligne=ligne||label.net||' '
  266.             end
  267.             else ligne=ligne||"-1"||' '
  268.         end
  269.         'IF(GETVAL(O),READTEXT(GETVAL(O)),PARTNAME(O))'
  270.         ligne=ligne||result
  271.         call writeln(file, ligne)
  272.         end
  273.     end
  274.     else leave i
  275.     end
  276.     analyse=""
  277.     do i=1 to objets
  278.     'FINDOBJ('i',4,-1,-1)'; i=result
  279.     if i>0 then do
  280.         'READTEXT('i')'; t=result
  281.         if left(t,10)=".ANALYSE: " then do
  282.         analyse=right(t,length(t)-10)
  283.         end
  284.     end
  285.     else leave
  286.     end
  287.     if analyse="" then do
  288.     'SELECT("Type of''analyse to do"+CHR(10)+"AC"+CHR(10)+"DC"+CHR(10)+"Transient")'
  289.     select
  290.         when result=1 then do
  291.         'SELECT("Type of variation"+CHR(10)+"Decade"+CHR(10)+"Octave"+CHR(10)+"Linear")'
  292.         select
  293.             when result=1 then do
  294.             f="DEC "; v="by decade"
  295.             end
  296.             when result=2 then do
  297.             f="OCT "; v="by octave"
  298.             end
  299.             when result=3 then do
  300.             f="LIN "; v="de test"
  301.             end
  302.             otherwise do
  303.             close(file)
  304.             return
  305.             end
  306.         end
  307.         'ASK("Number of points 'v'?")'
  308.         f=f||result
  309.         'ASK("What''s the begining frequency?")'
  310.         f=f||" "||result
  311.         'ASK("What''s the ending frequency?")'
  312.         analyse="AC "||f||' '||result
  313.         end
  314.         when result=2 then do
  315.         'ASK("What''s the source name to be swept?")'
  316.         f=result
  317.         'ASK("What''s the start value?")'
  318.         f=f||' '||result
  319.         'ASK("What''s the ending value?")'
  320.         f=f||' '||result
  321.         'ASK("What''s the increment value?")'
  322.         analyse="DC "||f||' '||result
  323.         end
  324.         when result=3 then do
  325.         'ASK("Time of simulation?")'; temps=result
  326.         'ASK("Simulation step?")'; pas=result
  327.         'ASK("Time to begin simulation?")'; d=result
  328.         analyse="tran "||pas||" "||temps||" "||d
  329.         end
  330.         otherwise
  331.         return
  332.     end
  333.     end
  334.     if analyse~="" then writeln(file,"."||analyse)
  335.     writeln(file,".END")
  336.     close(file)
  337.     'MESSAGE("Saving ended"):TITLE("")'
  338. return
  339.  
  340. connexion_broche: procedure
  341.     parse arg objet,broche
  342.     'PINCOL(O='objet',B='broche')'; xj=result
  343.     'PINLINE(O,B)'; yj=result
  344.     'FINDOBJ(1,2,'xj','yj')'; xl=result
  345.     if xl>0 then return xl
  346.     'FINDLINE(1,'xj','yj')'; xl=result
  347.     if xl<=0 then return 0
  348.     'FINDOBJ(1,7,'xj','yj')'
  349.     if result>0 then return xl
  350.     return 0
  351.  
  352. syntax:
  353. erreur=RC
  354. 'MESSAGE("Script SaveNets.AmiCAD:"+CHR(10)+"Syntax error"+CHR(10)+"in line 'SIGL'"+CHR(10)+"'errortext(erreur)'")'
  355. exit
  356.  
  357. error:
  358. 'MESSAGE("Script SaveNets.AmiCAD:"+CHR(10)+"Erreur in line 'SIGL'")'
  359. exit
  360.